package threadings;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yyx
 * Date: 2024-01-30
 * Time: 21:55
 */
public class ThreadDemo10 {
    volatile public static int flag = 0;

    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
           while (flag == 0){
               //空转
           }
           //结束循环打印
            System.out.println("结束循环,t1也结束");
        });
        Thread t2 = new Thread(()->{
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入一个非0整数");
            flag = scanner.nextInt();
        });
        t1.start();
        t2.start();
    }
}
